/** @file rsa.h
@brief This module contains the RSA algorithm */

/** \defgroup ProcessSteps Process steps
@{ */

/** \defgroup AuthObjects Authentication objects
@{ */

/** \defgroup RsaMod RSA object
@{ */

/*
   RSA keys and buffers implementation

 */

#ifndef __RSA_DEF__
#define __RSA_DEF__

 #define  MIN_RSA_MODULUS_BITS  320L /**< Minimal RSA modulus bits */
 #define  MAX_RSA_MODULUS_BITS  2048L /**< Maximal RSA modulus bits */

/* BEGIN SMO/ETU/05/20035/MA    global definition of keys length maximum */
 #define  MAX_KEYS_BITS  (1984/4) /**< Definition of keys length maximum  */
/* END SMO/ETU/05/20035/MA    global definition of keys length maximum */


/** Length of digit in bits */
#define RSA_DIGIT_BITS      32
/** Half length of digit in bits */
#define RSA_HALF_DIGIT_BITS 16

/** Length of digit in bytes */
#define RSA_DIGIT_LEN       (RSA_DIGIT_BITS / 8)

/** Maximum length in digits */
#define MAX_RSA_DIGITS ((MAX_RSA_MODULUS_LEN + RSA_DIGIT_LEN - 1) / RSA_DIGIT_LEN )


#define MAX_RSA_MODULUS_LEN  ((MAX_RSA_MODULUS_BITS + 7) / 8)
#define MAX_RSA_PRIME_BITS   ((MAX_RSA_MODULUS_BITS + 1) / 2)
#define MAX_RSA_PRIME_LEN    ((MAX_RSA_PRIME_BITS   + 7) / 8)

/** Maximum digits */
#define MAX_RSA_DIGIT       0xffffffffL
/** Half maximum digits */
#define MAX_RSA_HALF_DIGIT  0xffffL
/* Macros. */
/** Low digit half */
#define LOW_HALF(x)     (RSA_HALF_DIGIT)((x) & MAX_RSA_HALF_DIGIT)
/** High digit half */
#define HIGH_HALF(x)    (RSA_HALF_DIGIT)(((x) >> RSA_HALF_DIGIT_BITS) & MAX_RSA_HALF_DIGIT)
#define TO_HIGH_HALF(x) (((RSA_DIGIT)(x)) << RSA_HALF_DIGIT_BITS)
/** Most significant byte of digit 2 */
#define DIGIT_MSB(x)    (unsigned int)(((x) >> (RSA_DIGIT_BITS - 1)) & 1)
/** Most significant byte of digit 1 */
#define DIGIT_2MSB(x)   (unsigned int)(((x) >> (RSA_DIGIT_BITS - 2)) & 3)

#endif
/** @} */
/** @} */
/** @} */
